home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Precision Software Appli…tions Silver Collection 1
/
Precision Software Applications Silver Collection Volume One (PSM) (1993).iso
/
games
/
vga
/
boodfly.arj
/
BOODMISC.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1992-10-28
|
20KB
|
534 lines
#include "boodmisc.h"
#include <alloc.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include "xlib.h"
#include "xrect.h"
#include "xtext.h"
#include "xpoint.h"
extern int turns;
extern int score;
extern icon logo;
extern int numboodles, numgrumjugs;
extern boodlepiece ** boodles;
extern boodlepiece ** grumjugs;
void display(boodlepiece * my_actor, animap * mymap)
{
char * boodletype;
mymap->show(my_actor->mapx,my_actor->mapy, 225 - my_actor->squarex,150 - my_actor->squarey, 7,4, HiddenPageOffs);
x_rect_fill(370,20,380,220,HiddenPageOffs,0);
x_rect_fill(30,198,360,220, HiddenPageOffs, 0);
switch (my_actor->my_identity)
{
case BOODLE : boodletype = "Boodle"; break;
case BOODLINO : boodletype = "Boodlino"; break;
case BOODLEWIZ : boodletype = "BoodleWiz"; break;
case BOODLEBLASTER : boodletype = "BoodleBlaster"; break;
case BOODLETTAH : boodletype = "Boodlettah"; break;
case GRUMJUG : boodletype = "Grumjug"; break;
case DEAD : boodletype = "Grave"; break;
case CARRIEDGRUMJUG : boodletype = "Passenger"; break;
case GRUMBUGGY : boodletype = "GrumBuggy"; break;
case BROKEBUGGY : boodletype = "BrokeBuggy"; break;
case CURSOR : boodletype = "BlastCursor"; break;
case SAFEBOODLE : boodletype = "Safe Boodle!"; break;
}
my_actor->draw(30, 200, HiddenPageOffs);
x_printf(65,210, HiddenPageOffs, 10, "%s", boodletype);
x_printf(170,210,HiddenPageOffs, 10, "Move: %d", my_actor->movesleft);
x_printf(250, 210, HiddenPageOffs, 10, "Cargo:");
if (my_actor->cargo != NULL)
my_actor->cargo->draw(300,200, HiddenPageOffs);
if (my_actor->cargo2 != NULL)
my_actor->cargo2->draw(340,200, HiddenPageOffs);
x_page_flip(20,20);
}
void blast(boodlepiece * tobeblasted, boodlepiece * toblast)
{
boodle cursor(CURSOR); //could be just an animactor, but I'm tired.
cursor.mymap = tobeblasted->mymap;
cursor.mapx = tobeblasted->mapx;
cursor.mapy = tobeblasted->mapy;
cursor.squarex = cursor.squarey = 20;
cursor.put(tobeblasted->mapx, tobeblasted->mapy);
char exit = 0;
while ((exit != ' ') && (exit != 13))
{
if (!kbhit())
if (cursor.this_line == NULL)
cursor.addcommand(DO_NOTHING, 0,0,0,0); //so the "on" char. animates
if (kbhit())
{
exit = getch();
flushall();
cursor.remove();
if (exit == 0)
{
exit = getch();
switch(exit)
{
case 72 : cursor.mapy--; break;
case 80 : cursor.mapy++; break;
case 75 : cursor.mapx--; break;
case 77 : cursor.mapx++; break;
case 71 : cursor.mapy--; cursor.mapx--; break;
case 73 : cursor.mapy--; cursor.mapx++; break;
case 79 : cursor.mapy++; cursor.mapx--; break;
case 81 : cursor.mapy++; cursor.mapx++; break;
} //switch
}
if (((int)cursor.mapx - (int)tobeblasted->mapx) > 3) cursor.mapx--;
if (-((int)cursor.mapx - (int)tobeblasted->mapx) > 3) cursor.mapx++;
if (((int)cursor.mapy - (int)tobeblasted->mapy) > 3) cursor.mapy--;
if (-((int)cursor.mapy - (int)tobeblasted->mapy) > 3) cursor.mapy++;
if ((int)cursor.mapx < 0) cursor.mapx = 0;
if ((int)cursor.mapy < 0) cursor.mapy = 0;
cursor.put(cursor.mapx, cursor.mapy);
}
display(&cursor, cursor.mymap);
}
cursor.remove();
int deltax = ((cursor.mapx - tobeblasted->mapx) * cursor.mymap->squarewidth);
int deltay = ((cursor.mapy - tobeblasted->mapy) * cursor.mymap->squarewidth);
tobeblasted->addcommand(FINESLIDE, 6, 0, deltax, deltay);
tobeblasted->movesleft = 0;
toblast->spawn(new boodblast);
for (int counter = 0; counter < 8; ++counter)
display(toblast, toblast->mymap);
}
void spell(boodlepiece * caster)
{
event spellzap;
spellzap.mymap = caster->mymap;
spellzap.squarex = 23;
spellzap.squarey = 23;
spellzap.assign_event(1);
int height_counter, width_counter, x, y;
boodlepiece * target;
if (random(6) < 4)
{
for (height_counter = -3; height_counter <= 3; ++height_counter)
{
for (width_counter = -3; width_counter <= 3; ++width_counter)
{
x = (caster->mapx + width_counter) % (int)(caster->mymap->width);
y = (caster->mapy + height_counter) % (int)(caster->mymap->height);
x += (x < 0) ? caster->mymap->width : 0;
y += (y < 0) ? caster->mymap->height : 0;
caster->mymap->mapdata[x][y].my_terrain_type |= 16;
if (target = (boodlepiece *)caster->mymap->isinsquare(x,y,GRUMBUGGY))
{
target->assign_icon(BROKEBUGGY, ONEFACE);
spellzap.addat(x, y, 23, 23);
}
}
}
}
caster->movesleft = 0;
}
char commandloop(boodlepiece * myactor, animap * mymap)
{
boodlepiece * target;
boodlepiece * bombtoset = NULL;
char exit = 'd', stayhere = 1;
if (myactor->my_identity == GRUMBOMB)
myactor->move(CENTER);
if (myactor->my_identity == CARRIEDGRUMJUG)
stayhere = 0;
while (stayhere)
{
if (!kbhit())
if (myactor->this_line == NULL)
myactor->addcommand(DO_NOTHING, 0,0,0,0); //so the "on" char. animates
if (kbhit())
{
exit = getch();
flushall();
if (myactor->this_line == NULL)
{
if (exit == 0)
{
exit = getch();
switch(exit)
{
case 72 : myactor->move(NORTH); break;
case 80 : myactor->move(SOUTH); break;
case 75 : myactor->move(WEST); break;
case 77 : myactor->move(EAST); break;
case 71 : myactor->move(NORTHWEST); break;
case 73 : myactor->move(NORTHEAST); break;
case 79 : myactor->move(SOUTHWEST); break;
case 81 : myactor->move(SOUTHEAST); break;
} //switch
}
else
{
switch(exit)
{
case '+' :
case 'p' : myactor->pick_up(); break;
case '-' :
case 'D' :
case 'd' : myactor->drop(); break;
case 'B' :
case 'b' : if ((target = (boodlepiece *)myactor->isinsquare(BOODLEBLASTER)) &&
((myactor->my_identity == BOODLE) ||
(myactor->my_identity == BOODLINO) ||
(myactor->my_identity == BOODLEWIZ) ||
(myactor->my_identity == BOODLETTAH)))
blast(myactor, target);
stayhere = 0;
break;
case 'S' :
case 's' : if (myactor->cargo->my_identity == UNSETBOODLEBLASTER)
myactor->cargo->assign_icon(BOODLEBLASTER, ONEFACE);
if (myactor->cargo->my_identity == UNSETGRUMBOMB)
{
bombtoset = myactor->cargo;
}
if (myactor->cargo2->my_identity == UNSETGRUMBOMB)
{
bombtoset = myactor->cargo2;
}
myactor->drop(); break;
case 'R' :
case 'r' : if ((myactor->my_identity == GRUMJUG) &&
(target = (boodlepiece *)myactor->isinsquare(GRUMBUGGY)))
{
target->pick_up();
myactor->movesleft = 0;
}
break;
case 'C' :
case 'c' : if (myactor->my_identity == BOODLEWIZ)
spell(myactor); break;
case 'T' :
case 't' : tactical_map(mymap, myactor); break;
case '?' : help_screen(); break;
case 'Q' :
case 13 :
case ' ' : myactor->movesleft = 0; stayhere = 0; break;
case 'W' :
case 'w' : stayhere = 0; break;
} //switch
}
}
}
display(myactor, mymap);
if ((exit != 'Q') && (exit != ' ') && (exit != 13))
{
if (myactor->movesleft == 0)
{
stayhere = 0;
for(int counter = 0; counter < 10; ++counter)
display(myactor, mymap);
myactor->movesleft = -1;
}
if ((myactor->movesleft <= 0) && (exit != ' ') && (exit != 'b'))
{
if (((myactor->isinsquare(UNSETBOODLEBLASTER))
||(myactor->isinsquare(UNSETGRUMBOMB))
||(myactor->isinsquare(GRUMBUGGY))
||(myactor->isinsquare(BOODLEBLASTER))
||(myactor->cargo->my_identity == CARRIEDGRUMJUG)
||(myactor->cargo->my_identity == UNSETBOODLEBLASTER))
&&(myactor->my_identity != CARRIEDGRUMJUG))
stayhere = 1;
else (stayhere = 0);
}
if (myactor->my_identity == DEAD)
stayhere = 0;
}
}
if (bombtoset != NULL)
bombtoset->assign_icon(GRUMBOMB, ONEFACE);
return(exit);
}
int boodleturn(animap * mymap)
{
char exit;
int counter, totalmoves = 0, liveboodles = 0;
boodlepiece * myactor;
for (counter = 0; counter < numboodles; ++counter)
{
boodles[counter]->setmovement();
totalmoves += boodles[counter]->movesleft;
if ((boodles[counter]->my_identity == BOODLE) ||
(boodles[counter]->my_identity == BOODLINO) ||
(boodles[counter]->my_identity == BOODLEWIZ) ||
(boodles[counter]->my_identity == BOODLETTAH))
liveboodles++;
}
while (totalmoves > 0)
{
totalmoves = 0;
for (counter = 0; counter < numboodles; ++counter)
totalmoves += boodles[counter]->movesleft;
for (counter = 0; counter < numboodles; ++counter)
{
myactor = boodles[counter];
if ((myactor->movesleft > 0) && (myactor->my_identity != DEAD))
exit = commandloop(myactor, mymap);
if (exit == 'Q') return(0);
}
}
return(liveboodles);
}
void makenewgrumpiece(animap * mymap)
{
int counter;
boodlepiece * target; //not sure why, but wouldn't let me use pointer.
if (numgrumjugs < 100)
{
if (target = (boodlepiece *)mymap->isinsquare(16, 1, GRUMBUGGY))
grumjugs[numgrumjugs] = new grumjug;
else if (target = (boodlepiece *)mymap->isinsquare(16, 1, UNSETGRUMBOMB))
grumjugs[numgrumjugs] = new grumbuggy;
else grumjugs[numgrumjugs] = new grumbomb;
grumjugs[numgrumjugs]->squarex = random(10) + 10;
grumjugs[numgrumjugs]->squarey = random(10) + 10;
grumjugs[numgrumjugs]->mymap = mymap;
grumjugs[numgrumjugs]->put(16,1);
numgrumjugs += 1;
}
}
char grumturn(animap * mymap)
{
char exit;
int counter, totalmoves = 0;
boodlepiece * myactor;
for (counter = 0; counter < numgrumjugs; ++counter)
{
grumjugs[counter]->setmovement();
totalmoves += grumjugs[counter]->movesleft;
}
while (totalmoves > 0)
{
totalmoves = 0;
for (counter = 0; counter < numgrumjugs; ++counter)
if (grumjugs[counter]->my_identity != CARRIEDGRUMJUG)
totalmoves += grumjugs[counter]->movesleft;
for (counter = 0; counter < numgrumjugs; ++counter)
{
myactor = grumjugs[counter];
if ((myactor->movesleft > 0) && (myactor->my_identity != DEAD))
exit = commandloop(myactor, mymap);
if (exit == 'Q') return('Q');
}
}
for (counter = 0; counter < numgrumjugs; ++counter)
if (grumjugs[counter]->my_identity == BROKEBUGGY)
grumjugs[counter]->assign_icon(GRUMBUGGY, TWOFACE);
if (turns % 3 == 0)
makenewgrumpiece(mymap);
return(exit);
}
void tactical_map(animap * mymap, boodlepiece * myactor)
{
int ledge = 40, top = 40, color = 0;
x_rect_fill(ledge - 1,top - 1,ledge + 1 + (mymap->width * 2), top + 1 + (mymap->height * 2), VisiblePageOffs, 0);
for (int width_counter = 0; width_counter < mymap->width; ++width_counter)
{
for (int height_counter = 0; height_counter < mymap->height; ++height_counter)
{
switch (mymap->mapdata[width_counter][height_counter].my_terrain_type & 239)
{
case GRASS: color = 43; break;
case MOUNTAINS: color = 8; break;
case WATER: color = 63; break;
case VALLEY: color =111; break;
}
x_rect_fill(ledge + (width_counter*2), top + (height_counter *2), ledge + (2*width_counter) + 2, top + (2*height_counter) + 2, VisiblePageOffs, color);
}
}
for (int counter = 0; counter < numboodles; ++counter)
x_rect_fill(ledge + (boodles[counter]->mapx *2), top + (boodles[counter]->mapy*2), ledge + (2*boodles[counter]->mapx) + 1, top + (2*boodles[counter]->mapy) + 1, VisiblePageOffs, 58);
for (counter = 0; counter < numgrumjugs; ++counter)
x_rect_fill(ledge + (grumjugs[counter]->mapx *2), top + (grumjugs[counter]->mapy*2), ledge + (2*grumjugs[counter]->mapx) + 1, top + (2*grumjugs[counter]->mapy) + 1, VisiblePageOffs, 28);
x_rect_fill(ledge + (myactor->mapx *2), top + (myactor->mapy*2), ledge + (2*myactor->mapx) + 1, top + (2*myactor->mapy) + 1, VisiblePageOffs, 15);
while (!kbhit());
getch();
}
void allocate_forces(animap * mymap, int boodlepoints, int grumpoints)
{
int numboodlettahs = 1, numplainboodles = 0, numboodlinos = 0, numboodlewizzes = 0, numboodleblasters = 0;
int numgrumkings = 1, numplaingrumjugs = 0, numgrumbuggies = 0, numgrumbombs = 0;
numboodles = numgrumjugs = 0;
int randomx=0, randomy=0; //for grumjug placement
int randomnum, counter, stepcounter, boodleside = random(2);
for (int height_counter = 1; height_counter < 20; ++height_counter)
{
mymap->setsquare(((boodleside == 1) ? 1 : 28), height_counter, VALLEY);
mymap->setsquare(((boodleside == 1) ? 2 : 29), height_counter, VALLEY);
}
char commandchar = 0;
x_rect_fill(0,0,340,220, VisiblePageOffs, 0);
factor::ficon_table[BOODLETTAH][CENTER].draw(40,40,VisiblePageOffs);
factor::ficon_table[BOODLE][CENTER].draw(40, 72, VisiblePageOffs);
factor::ficon_table[BOODLINO][CENTER].draw(40,104, VisiblePageOffs);
factor::ficon_table[BOODLEWIZ][CENTER].draw(40,136, VisiblePageOffs);
factor::ficon_table[BOODLEBLASTER][CENTER].draw(40, 168, VisiblePageOffs);
x_set_font(0);
x_printf(50,20, VisiblePageOffs, 31, "Players: Allocate your forces!");
x_set_font(2);
x_printf(60,46, VisiblePageOffs, 10, " Boodlettah");
x_printf(60,78, VisiblePageOffs, 10, "A: Boodle(1)");
x_printf(60,110, VisiblePageOffs, 10, "B: Boodlino(4)");
x_printf(60,142, VisiblePageOffs, 10, "C: BoodleWiz(6)");
x_printf(60,174, VisiblePageOffs, 10, "D: BoodleBlaster(4)");
factor::ficon_table[GRUMKING][CENTER].draw(290, 40, VisiblePageOffs);
factor::ficon_table[GRUMJUG][CENTER].draw(290, 72, VisiblePageOffs);
factor::ficon_table[GRUMBUGGY][CENTER].draw(290,104, VisiblePageOffs);
factor::ficon_table[GRUMBOMB][CENTER].draw(290,136, VisiblePageOffs);
x_printf(180,46, VisiblePageOffs, 10, "GrumKing");
x_printf(180,78, VisiblePageOffs, 10, "GrumJug(3) :1");
x_printf(180,110, VisiblePageOffs, 10, "GrumBuggy(3):2");
x_printf(180,142, VisiblePageOffs, 10, "GrumBomb(3) :3");
while (((boodlepoints > 0) || (grumpoints > 0)) && (commandchar != 'Q'))
{
x_bgprintf(30, 46, VisiblePageOffs, 10, 0, "%d", numboodlettahs);
x_bgprintf(30, 78, VisiblePageOffs, 10, 0, "%d", numplainboodles);
x_bgprintf(30,110, VisiblePageOffs, 10, 0, "%d", numboodlinos);
x_bgprintf(30,142, VisiblePageOffs, 10, 0, "%d", numboodlewizzes);
x_bgprintf(30,174, VisiblePageOffs, 10, 0, "%d", numboodleblasters);
x_bgprintf(310, 46, VisiblePageOffs, 10, 0, "%d", numgrumkings);
x_bgprintf(310, 78, VisiblePageOffs, 10, 0, "%d", numplaingrumjugs);
x_bgprintf(310,110, VisiblePageOffs, 10, 0, "%d", numgrumbuggies);
x_bgprintf(310,142, VisiblePageOffs, 10, 0, "%d", numgrumbombs);
x_bgprintf(55,35, VisiblePageOffs, 10,0,"Points: %d ", boodlepoints);
x_bgprintf(210, 35, VisiblePageOffs, 10,0,"Points: %d ", grumpoints);
commandchar = getch();
switch(commandchar)
{
case 'a' :
case 'A' : if (boodlepoints > 0){++numplainboodles; boodlepoints -= 1;} break;
case 'b' :
case 'B' : if (boodlepoints > 0){++numboodlinos; boodlepoints -= 4;} break;
case 'c' :
case 'C' : if (boodlepoints > 0){++numboodlewizzes; boodlepoints -= 6;} break;
case 'd' :
case 'D' : if (boodlepoints > 0){++numboodleblasters; boodlepoints -= 4;} break;
case '1' : if (grumpoints > 0){++numplaingrumjugs; grumpoints -= 3;} break;
case '2' : if (grumpoints > 0){++numgrumbuggies; grumpoints -= 3;} break;
case '3' : if (grumpoints > 0){++numgrumbombs; grumpoints -= 3;} break;
}
}
numboodles = numboodlettahs + numplainboodles + numboodlinos + numboodlewizzes + numboodleblasters;
numgrumjugs = numgrumkings + numplaingrumjugs + numgrumbuggies + numgrumbombs;
boodles = new boodlepiece *[numboodles];//[numboodles];
grumjugs = new boodlepiece *[(numgrumjugs < 100) ? 100 : numgrumjugs];
for (counter = 0; counter < numboodlettahs; ++counter)
boodles[counter] = new boodlettah;
for (stepcounter = counter;counter < stepcounter + numplainboodles; ++counter)
boodles[counter] = new boodle;
for (stepcounter = counter;counter < stepcounter + numboodlinos; ++counter)
boodles[counter] = new boodlino;
for (stepcounter = counter;counter < stepcounter + numboodlewizzes; ++counter)
boodles[counter] = new boodlewiz;
for (stepcounter = counter;counter < stepcounter + numboodleblasters; ++counter)
boodles[counter] = new boodleblaster;
for (counter = 0; counter < numgrumkings; ++counter)
grumjugs[counter] = new grumking;
for (stepcounter = counter;counter < stepcounter + numgrumbuggies; ++counter)
grumjugs[counter] = new grumbuggy;
for (stepcounter = counter;counter < stepcounter + numplaingrumjugs; ++counter)
grumjugs[counter] = new grumjug;
for (stepcounter = counter;counter < stepcounter + numgrumbombs; ++counter)
grumjugs[counter] = new grumbomb;
for (counter = 0; counter < numboodles; ++counter)
{
boodles[counter]->squarex = random(10) + 10;
boodles[counter]->squarey = random(10) + 10;
boodles[counter]->mymap = mymap;
boodles[counter]->put(((boodleside == 0) ? 1 : 28) + random(2), random(19)+1);
}
grumjugs[0]->squarex = 20;
grumjugs[0]->squarey = 20;
grumjugs[0]->mymap = mymap;
grumjugs[0]->put(15,1);
for (counter = 1; counter < numgrumjugs; ++counter)
{
grumjugs[counter]->squarex = random(10) + 10;
if (grumjugs[counter]->my_identity == GRUMBUGGY)
grumjugs[counter]->squarex = 23;
grumjugs[counter]->squarey = random(10) + 10;
grumjugs[counter]->mymap = mymap;
randomx = random(26) + 2;
randomy = random(19) + 1;
while (mymap->mapdata[randomx][randomy].my_terrain_type != GRASS)
{
randomx = random(26) + 2;
randomy = random(19) + 1;
}
grumjugs[counter]->put(randomx, randomy);
}
}
void showlogo(animap * mymap)
{
mymap->show(15,5,185,140, 6,4, VisiblePageOffs);
logo.showmasked(75,50,VisiblePageOffs);
x_bgprintf(95,120, VisiblePageOffs, 15,1, "Press a key to begin play.");
getch();
}
void endgame(void)
{
x_rect_fill(70,50, 330, 190, VisiblePageOffs, 0);
logo.showmasked(95,55,VisiblePageOffs);
if (score > 3)
{
factor::ficon_table[BOODLETTAH][CENTER].draw(90,90,VisiblePageOffs);
x_printf(95,120,VisiblePageOffs, 15, "And so, their new homesteads est-");
x_printf(95,130,VisiblePageOffs, 15, "ablished, the Boodles settled down");
x_printf(95,140,VisiblePageOffs, 15, "to a long, peaceful, happy life; ");
x_printf(95,150,VisiblePageOffs, 15, "and only poems and stories now tell");
x_printf(95,160,VisiblePageOffs, 15, "of the epic Flight of the Boodles.");
}
else
{
factor::ficon_table[GRUMKING][CENTER].draw(90,90,VisiblePageOffs);
x_printf(95,120,VisiblePageOffs, 15, "What the Rotsnort plague had failed");
x_printf(95,130,VisiblePageOffs, 15, "to do, the happy Grumjugs had");
x_printf(95,140,VisiblePageOffs, 15, "done, and they rejoiced, hopping");
x_printf(95,150,VisiblePageOffs, 15, "in mad dances as they celebrated");
x_printf(95,160,VisiblePageOffs, 15, "their victory over the invasive and");
x_printf(95,170,VisiblePageOffs, 15, "terrifying Flight of the Boodles.");
}
getch();
}
void help_screen(void)
{
x_rect_fill(70,30, 330, 200, VisiblePageOffs, 0);
logo.showmasked(95,35,VisiblePageOffs);
x_printf(95,100,VisiblePageOffs, 15, "Arrow keys: Movement/attack ");
x_printf(95,110,VisiblePageOffs, 15, "space, cr: end turn (this piece)");
x_printf(95,120,VisiblePageOffs, 15, "W: wait to finish move");
x_printf(95,130,VisiblePageOffs, 15, "T: tactical map display");
x_printf(95,140,VisiblePageOffs, 15, "P,+: pick up (blaster, bomb, jug)");
x_printf(95,150,VisiblePageOffs, 15, "D,-: drop cargo carried (doesn't set)");
x_printf(95,160,VisiblePageOffs, 15, "S: set (grumbomb, boodleblaster)");
x_printf(95,170,VisiblePageOffs, 15, "R: ride (grumjug in grumbuggy)");
x_printf(95,180,VisiblePageOffs, 15, "B: blast with boodleblaster) ");
x_printf(95,190,VisiblePageOffs, 15, "C: cast spell (boodlewizzes)");
getch();
}